package org.testis.gui.mvc.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;


/**
 * 
 * @author Cahit Emir Erel
 */
public abstract class AbstractModel
{

    protected PropertyChangeSupport m_propertyChangeSupport;


    public AbstractModel()
    {
        m_propertyChangeSupport = new PropertyChangeSupport(this);
    }


    /**
     * Adds a property change listener to the observer list.
     * @param l The property change listener
     */
    public void addPropertyChangeListener(PropertyChangeListener l)
    {
        m_propertyChangeSupport.addPropertyChangeListener(l);
    }


    /**
     * Removes a property change listener from the observer list.
     * @param l The property change listener
     */
    public void removePropertyChangeListener(PropertyChangeListener l)
    {
        m_propertyChangeSupport.removePropertyChangeListener(l);
    }


    /**
     * Fires an event to all registered listeners informing them that a property in
     * this model has changed.
     * @param propertyName The name of the property
     * @param oldValue The previous value of the property before the change
     * @param newValue The new property value after the change
     */
    protected void firePropertyChange(String propertyName,
                                       Object oldValue,
                                       Object newValue)
    {
        m_propertyChangeSupport.firePropertyChange(propertyName,
                                                   oldValue,
                                                   newValue);
    }
}
    

